home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
001-025
/
scopedisk1
/
getopt
/
gotest.c
< prev
Wrap
C/C++ Source or Header
|
1995-03-18
|
967b
|
40 lines
/* GOtest.c - A test program to exercise getopt().
usage: GOtest -a -b -c -d argument_d -e argument_e -f argument_f argsapoppin
*/
#include <stdio.h>
#include "getopt.h"
main(argc, argv)
int argc;
char *argv[];
{
int i, option;
char *optstring;
extern char *optarg;
extern int optind, opterr, optopt;
/* optstring is a string of valid options for this program.
a, b, & c are only flags, and hence have no arguments.
The colons (:) following d, e, & f indicate that these
three options require arguments.
*/
optstring = "abcd:e:f:";
printf("\noptstring: \"%s\", opterr: %d\n", optstring, opterr);
/* Parse the options (if any) */
while ((option = getopt(argc, argv, optstring)) != EOF) {
printf("getopt() returned '%c', optopt: '%c', optarg: \"%s\", optind: %d\n",
option, optopt, optarg, optind);
}
/* Display the remaining arguments (if any) */
for (i = optind; i < argc; i++)
printf("argv[%d]: \"%s\"\n", i, argv[i]);
} /* end main */